package com.chinadci.smartcommunitysystembackstage.controller;

import com.chinadci.smartcommunitysystembackstage.entity.ScsNotice;
import com.chinadci.smartcommunitysystembackstage.service.ScsAdminService;
import com.chinadci.smartcommunitysystembackstage.service.ScsNoticeService;
import com.chinadci.smartcommunitysystembackstage.util.DateTime;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
@Api("建业E家")
public class ScsNoticeController {
    @Autowired
    private ScsNoticeService service;

    @Autowired
    private ScsAdminService admin;

    //显示全部社区公告
    @ApiOperation(value = "显示全部社区公告")           //swagger
    @ApiImplicitParam(name = "title",value = "公告标题")       //表明要传入的参数
    @RequestMapping(value = "/api/sqggfind",method = RequestMethod.GET)
    public Map Finds(String title){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Find(title));
        return map;
    }

    //新增社区公告
    @ApiOperation(value = "新增社区公告")           //swagger
    @ApiImplicitParam(name = "ScsNotice",value = "对象")       //表明要传入的参数
    @RequestMapping(value = "/api/xzgg",method = RequestMethod.POST)
    public Map Insert(ScsNotice scs){
        Map<String,Object> map=new HashMap<>();
        if (admin.find(scs.getName())==null){
            map.put("user",0);      //如果是0的话,那就是新增公告的时候姓名输入不正确管理员表里没有这个人
            return map;
        }
        scs.setAId(admin.find(scs.getName()).getAId());
        scs.setNReleasetime(DateTime.GetTime());
        map.put("user",1);          //如果是0的话,那就是新增公告的时候姓名输入正确管理员表里有这个人
        map.put("data",service.Insert(scs));
        return map;
    }

    //删除社区公告
    @ApiOperation(value = "删除社区公告")           //swagger
    @ApiImplicitParam(name = "title",value = "公告标题")       //表明要传入的参数
    @RequestMapping(value = "/api/scgg",method = RequestMethod.POST)
    public Map Del(int id){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Del(id));
        return map;
    }

    //修改社区公告
    @ApiOperation(value = "修改社区公告")           //swagger
    @ApiImplicitParam(name = "ScsNotice",value = "对象")       //表明要传入的参数
    @RequestMapping(value = "/api/xggg",method = RequestMethod.POST)
    public Map Del(ScsNotice scs){
        Map<String,Object> map=new HashMap<>();
        scs.setNReleasetime(DateTime.GetTime());
        map.put("data",service.Update(scs));
        return map;
    }

    //修改社区公告的时候查询
    @ApiOperation(value = "修改社区公告")           //swagger
    @ApiImplicitParam(name = "id",value = "社区公告编号")       //表明要传入的参数
    @RequestMapping(value = "/api/xgcxgg",method = RequestMethod.GET)
    public Map Finds(int id){
        Map<String,Object> map=new HashMap<>();
        map.put("data",service.Finds(id));
        return map;
    }
}
